<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/9/15
 * Time: 17:15
 */

class QueryInfo extends CI_Model
{
    function query($data)
    {
        $result = array('result' => 0, 'data' => null);
        if ($data) {
            //Post Data
            $sql = 'SELECT id,name from ws_baseinfo WHERE school=' . $data["school"] . ' AND grade=' . $data["grade"] . ' AND class=' . $data["class"];
            $query = $this->db->query($sql);
            if ($query) {
                $result['result'] = true;
                $result['data'] = $query->result_array();
            }
        } else {
            //Get Query
            //school
            $sql = /** @lang text */
                "select name from ws_dict_school";
            $query = $this->db->query($sql);
            $school = ($query->result_array());

            //grade
            $sql = /** @lang text */
                "select name from ws_dict_grade";
            $query = $this->db->query($sql);
            $grade = $query->result_array();

            //class
            $sql = /** @lang text */
                "select name from ws_dict_class";
            $query = $this->db->query($sql);
            $class = $query->result_array();

            //pos
            $sql = /** @lang text */
                "select name from ws_dict_pos";
            $query = $this->db->query($sql);
            $pos = $query->result_array();

            if ($grade && $class && $school && $pos) {
                $result['result'] = true;
            }
            $result['data'] = array(
                'school' => $school,
                'grage' => $grade,
                'class' => $class,
                'pos' => $pos
            );
        }
        return json_encode($result);
    }
}